<?php 
/**
 * Bdat Site development
 * @author Will Skates
 */

require_once 'blockmodel.php';

/**
 * 
 * Establish base attributes and functionality for all pieces of content which have been aggregated.
 * @author Will Skates
 *
 */
class AggregatedContent extends BlockModel {
	
	public $approved;
	public $published;

	public static $fieldList = array(
		'approved'=>array(array('approved'),array('approved','published','sticky')),
		'published'=>array(array('approved','published'),array('published','sticky')),
		'stickied'=>array(array('approved','approved','sticky'),array('sticky'))
	);
	
	/*----------------------------------------------------------------------------------------------------*/
	
	/**
	 * Change the approval status of an item.
	 * @param String	$name		- The approval raiting that you want to set.
	 * @param Boolean	$condition	- What you want to set that condition to.
	 */
	public function changeApproval( $name, $condition = false ) {
		
		
		if ($condition == false) {$loc = true;} else {$loc = false;}
		
		//Get the fields that have to be set according to the condition we want to set.
		$fields = self::$fieldList[$name][(Int)$loc];
		
		//Compose an update query base upon that.
		$sql = 'UPDATE ' . $this->ctable . ' SET ';
		
		$params = array();
		foreach ($fields as $field ) {
			$params[] = '`' . $field . '`= ' . (Int)$condition;
		}
		
		$sql .= implode(',', $params) . ' WHERE uid=' . $this->uid;
		
		//Run the query.
		$this->db->query($sql);
		
	}
	
	/*----------------------------------------------------------------------------------------------------*/
	
	/**
	 * Set the approved flag of an item.
	 * @param Boolean	$condition	- Whether you want an item to be approved or not.
	 */
	public function approved($condition = false)
	{
		$this->changeApproval('approved',$condition);
	}
	
	/*----------------------------------------------------------------------------------------------------*/
	
	/**
	 * Set the publish flag of an item.
	 * @param Boolean	$condition	- Whether you want an item to be published or not.
	 */
	public function published($condition = false)
	{
		$this->changeApproval('published',$condition);
	}
	
	/*----------------------------------------------------------------------------------------------------*/
	
	/**
	 * Set the stickied flag of an item.
	 * @param Boolean	$condition	- Whether you want an item to be stickied or not.
	 */
	public function stickied($condition = false)
	{
		$this->changeApproval('stickied',$condition);
	}
	
	/*----------------------------------------------------------------------------------------------------*/
	
}

/*----------------------------------------------------------------------------------------------------*/